package pl.poznan.put.cs.idss.particlefilter.enviroment;

import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import pl.poznan.put.cs.idss.particlefilter.agent.Agent;

/**
 * Klasa repreentująca latarnie morską.
 * 
 * @author Kornel Lewandowski
 * 
 */
public class Lighthouse {

	private Image lighthouseImage;
	private Image dark;
	private Image bright;
	private Point pos = new Point();
	private boolean isLighting = false;

	/**
	 * Konstruktor, strartuje Timer i wczytuje obrazki.
	 * 
	 * @param map
	 *            - WorldMap, mapa środowiska, na którym działą latarnia.
	 * @param isLightning
	 * @throws InterruptedException
	 * @throws IOException
	 */
	public Lighthouse(WorldMap map, int x, int y) throws InterruptedException,
			IOException {

		this.pos.x = x;
		this.pos.y = y;
		setLighthouseImage();
		switchImage();
	}

	public Image getLighthouseImage() {
		return lighthouseImage;
	}

	/**
	 * Wczytuje obrazki z pliku.
	 * 
	 * @throws IOException
	 */
	private void setLighthouseImage() throws IOException {
		dark = Toolkit.getDefaultToolkit().getImage(
				(Agent.class.getResource("/lighthouse-dark.png")));
		bright = Toolkit.getDefaultToolkit().getImage(
				(Agent.class.getResource("/lighthouse-bright.png")));
	}

	/**
	 * Zmiana obrazków - świecąca/zgaszona latarnia.
	 */
	public void switchImage() {
		if (lighthouseImage == dark) {
			setLight(true);
		} else {
			setLight(false);
		}
	}

	public void setLight(boolean light) {
		if (light == true) {
			lighthouseImage = bright;
			this.isLighting = true;
		} else {
			lighthouseImage = dark;
			this.isLighting = false;
		}

	}

	public boolean isLighting() {
		return isLighting;
	}

	public int getX() {
		return pos.x;
	}

	public int getY() {
		return pos.y;
	}

	public Point getPos() {
		return pos;
	}
}
